package com.yxkj.railservicer.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yxkj.railservicer.R;
import com.yxkj.railservicer.bean.SubOrderDetailBean;

import java.util.ArrayList;
import java.util.List;


public class GridGoodsAdapter<T> extends BaseAdapter {

    private Context mContext;
    private List<T> mList;

    public GridGoodsAdapter(Context context, List<T> mList) {
        this.mContext = context;
        this.mList = mList;
        if (this.mList == null) {
            this.mList = new ArrayList<T>();
        }
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gv_goods, null);

            viewHolder.item_record = (TextView) convertView.findViewById(R.id.item_record);
            viewHolder.item_count = (TextView) convertView.findViewById(R.id.item_count);
            viewHolder.item_price = (TextView) convertView.findViewById(R.id.item_price);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        SubOrderDetailBean data = (SubOrderDetailBean) mList.get(position);
        viewHolder.item_record.setText(data.getProductName());
        viewHolder.item_count.setText("×" + data.getProductCount());
        viewHolder.item_price.setText("￥" + data.getTotalPrice());

        viewHolder.item_record.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        return convertView;
    }

    class OnitemListener implements OnClickListener {

        private int position;
        private Object obj;

        public OnitemListener(int position, Object obj) {
            this.position = position;
            this.obj = obj;
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.item_record:
                    String info = (String) obj;
//				((SearchActivity)mContext).searchData(info);
                    break;
                default:
                    break;
            }
        }

    }

    class ViewHolder {
        TextView item_record;
        TextView item_count;
        TextView item_price;
    }

}
